/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package message.handler;

/**
 *
 * @author kinder
 */
import message.Message;
import java.util.StringTokenizer;
import util.TypeHandler;

public class FileBackEndHandler implements MessageHandler{

    private String[] data;
    private String ext;
    private String hostname;
    private String path;
    private String cmd;
    private String fileName;
    private boolean result = true;

    public void handleMessage(Message m) throws Exception

    {
        data = m.retData();
        ext = data[0];
        hostname = data[1];
        path = data[2];
        cmd = data[3];

        StringTokenizer stringTokenizer = new StringTokenizer(path, "/");
        while(stringTokenizer.hasMoreElements())
        {
            fileName = stringTokenizer.nextToken();
        }

        System.out.println("ARRIVED PACK: " + m.getId() + " " + ext + " " + hostname + " "
                + path + " " + cmd);

        TypeHandler inputFilter = new TypeHandler();
        inputFilter.activeFilter(this.ext, this.path, this.fileName, this.cmd);

        if(result)
            m.getSockOutput().println("OK");
        else
            m.getSockOutput().println("OK");

    }

}
